package com.enki.cigarettes.repository;

import com.enki.cigarettes.entity.OrderT;
import com.enki.cigarettes.statics.StaticKeys;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * @author WCS.Wang
 * @version V1.0
 * @Package com.handsure.aec.customer.repository
 * @Name e-cigarettes-shop-api-module
 * @Description: TODO 订单数据层
 * @date 2018/9/29
 */
public interface OrderTRepository extends PagingAndSortingRepository<OrderT, String> {

    // 详情
    OrderT findOneById(String id);

    // 订单详情
    OrderT findOneByIdAndUserTIdAndRemoved(String id, String userTId, boolean removed);

    // 拆分订单支付时统一标识
    List<OrderT> findByOrderPaymenId(String paymentId);

    // 拆分订单支付时统一标识
    List<OrderT> findByOrderPaymenIdAndUserTIdAndRemoved(String paymentId, String userTId, boolean removed);

    // 分页查询
    Page<OrderT> findAll(Specification<OrderT> specification, Pageable pageable);

    // 数量统计
    long count(Specification<OrderT> specification);

    // 根据用户ID统计
    long countByUserTIdAndFirstOrder(String userTId, boolean firstOrder);

    // 用户首单信息
    OrderT findFirstByUserTIdAndFirstOrder(String userTId, boolean firstOrder);
}
